package com.cardvalue.sys.tool;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
//com.cardvalue.sys.tool.MViewPager
/**
 * 上下滑动
 * Created by cardvalue on 2016/5/6.
 */
public class MViewPager extends ViewPager{
    private Context context;
    private int f=-1;
    private boolean isflag=true;
    private boolean isf=false;
    private float start=0;
    private float startX=0;
    private boolean isLeftRight=false;
    public MViewPager(Context context) {
        super(context);
        this.context=context;
    }

    public MViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(ev.getAction()==MotionEvent.ACTION_DOWN){//按下
            start=ev.getY();
            startX=ev.getX();
        }

        if(ev.getAction()==MotionEvent.ACTION_HOVER_MOVE){
            int st=(int)(startX-ev.getX());
            if(st>100 || st<-100){
                isLeftRight = true;
            }else{
                isLeftRight = false;
            }
        }


        if(isflag && !isLeftRight){
            Float ff=new Float(start-ev.getY());
            int i=ff.intValue();
            if(i>50){//向上的动画
                if(f!=0){
                    f = 0 ;
                    // upAnimation();
                    isflag=false;
                    isf=false;
                    return true;
                }
            }
        }else{
            Float ff=new Float(start-ev.getY());
            int i=ff.intValue();
            if(i<-50){//向下
                if(isf=false){
                    if(f!=1 && f!=-1){
                        f = 1;
                        //  downAnimation();
                        isflag=true;
                    }
                }
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    //向上动画
    public void upAnimation(){

    }


    //向下动画
    public void downAnimation(){}

}
